package com.yanqu.road.server.logic.activity.condition.normal;

import com.yanqu.road.entity.activity.ActivityConditionInfo;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.config.goods.MallInfo;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.enums.eShopType;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.task.TaskModule;
import com.yanqu.road.server.logic.activity.BaseActivityData;
import com.yanqu.road.server.logic.activity.condition.BaseActivityCondition;
import com.yanqu.road.server.manger.config.MallMgr;

import java.math.BigInteger;

/**
 * 充值买道具活动
 */
public class RechargeItemActivityCondition extends BaseActivityCondition {

	public RechargeItemActivityCondition(ActivityInfo activityInfo, ActivityConditionInfo activityConditionInfo, BaseActivityData baseActivityData) {
		super(activityInfo, activityConditionInfo, baseActivityData);
	}

	@Override
	public void addTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().addListener(eGamePlayerEventType.RechargeItem.getValue(), handle);
	}

	@Override
	public void removeTrigger(GamePlayer player) {
		player.getModule(TaskModule.class).getGameEvent().removeListener(eGamePlayerEventType.RechargeItem.getValue(), handle);
	}

	public boolean isCompleted(GamePlayer player) {
		return getValue().compareTo(activityConditionInfo.getParamList().get(3)) >= 0;
	}

	@Override
	protected void player_BoardLevelHandle(Object object) {
		int mallId = (int)object;
		if(mallId == activityConditionInfo.getParamList().get(2).intValue()){
			MallInfo mallInfo = MallMgr.getMallInfoByMallId(mallId);
			if(null != mallInfo && mallInfo.getShopType() == eShopType.SpecialMall.getValue()){
				getSpecialActivityReward();
			}else {
				getReward();
				if (activityInfo.getType() == eActivityType.NewRechargeActivity.getValue()) {
					setValue(BigInteger.ONE);
				}
			}
		}
	}
}
